/*   1:    */ package org.intellij.images.options.impl;
/*   2:    */ 
/*   3:    */

import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.fileChooser.FileChooser;
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
import com.intellij.openapi.util.NullableComputable;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.ui.ColorPanel;
import com.intellij.ui.DocumentAdapter;
import com.intellij.util.Consumer;
import org.intellij.images.ImagesBundle;
import org.intellij.images.options.*;

import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.DocumentEvent;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import javax.swing.text.Position;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.List;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */
/*  10:    */
/*  11:    */
/*  12:    */
/*  13:    */
/*  14:    */
/*  15:    */
/*  16:    */
/*  17:    */
/*  18:    */
/*  19:    */
/*  20:    */
/*  21:    */
/*  22:    */
/*  23:    */
/*  24:    */
/*  25:    */
/*  26:    */
/*  27:    */
/*  28:    */
/*  29:    */
/*  30:    */
/*  31:    */
/*  32:    */
/*  33:    */
/*  34:    */
/*  35:    */
/*  36:    */
/*  37:    */
/*  38:    */
/*  39:    */
/*  40:    */
/*  41:    */
/*  42:    */ 
/*  43:    */ final class OptionsUIForm
/*  44:    */ {
/*  45:    */   private JPanel a;
/*  46:    */   private JCheckBox b;
/*  47:    */   private JLabel c;
/*  48:    */   private JSpinner d;
/*  49:    */   private JLabel e;
/*  50:    */   private JSpinner f;
/*  51:    */   private JCheckBox g;
/*  52:    */   private JSpinner h;
/*  53:    */   private JLabel i;
/*  54:    */   private JCheckBox j;
/*  55:    */   private JCheckBox k;
/*  56:    */   private JSpinner l;
/*  57:    */   private JLabel m;
/*  58:    */   private JSpinner n;
/*  59:    */   private JLabel o;
/*  60:    */   private JLabel p;
/*  61:    */   private ColorPanel q;
/*  62:    */   private JLabel r;
/*  63:    */   private JLabel s;
/*  64:    */   private ColorPanel t;
/*  65:    */   private ColorPanel u;
/*  66:    */   private JLabel v;
/*  67:    */   private TextFieldWithBrowseButton w;
/*  68:    */   private final Options x;
/*  69:    */   
/*  70:    */   OptionsUIForm()
/*  71:    */   {
/*  72: 79 */     a();this.x = new OptionsImpl();
/*  73:    */     
/*  74:    */ 
/*  75:    */ 
/*  76: 83 */     this.j.setText(ImagesBundle.message("enable.mousewheel.zooming", new Object[] { SystemInfo.isMac ? "Cmd" : "Ctrl" }));
/*  77:    */     
/*  78:    */ 
/*  79: 86 */     this.c.setLabelFor(this.d);
/*  80: 87 */     this.e.setLabelFor(this.f);
/*  81: 88 */     this.i.setLabelFor(this.h);
/*  82: 89 */     this.m.setLabelFor(this.l);
/*  83: 90 */     this.o.setLabelFor(this.n);
/*  84: 91 */     this.p.setLabelFor(this.q);
/*  85: 92 */     this.r.setLabelFor(this.u);
/*  86: 93 */     this.s.setLabelFor(this.t);
/*  87: 94 */     this.v.setLabelFor(this.w);
/*  88:    */     
/*  89:    */ 
/*  90: 97 */     this.k.addItemListener(new LinkEnabledListener(new JComponent[] { this.o, this.n, this.m, this.l }));
/*  91:    */     
/*  92:    */ 
/*  93:    */ 
/*  94:    */ 
/*  95:    */ 
/*  96:    */ 
/*  97:104 */     this.d.setModel(new SpinnerNumberModel(3, 2, 8, 1));
/*  98:105 */     this.f.setModel(new SpinnerNumberModel(1, 1, 100, 1));
/*  99:106 */     this.h.setModel(new SpinnerNumberModel(5, 1, 100, 1));
/* 100:107 */     this.l.setModel(new SpinnerNumberModel(ZoomOptions.DEFAULT_PREFFERED_SIZE.width, 1, 9999, 1));
/* 101:108 */     this.n.setModel(new SpinnerNumberModel(ZoomOptions.DEFAULT_PREFFERED_SIZE.height, 1, 9999, 1));
/* 102:    */     
/* 103:    */ 
/* 104:111 */     this.b.addItemListener(new CheckboxOptionsListener("Editor.Grid.showDefault", null));
/* 105:112 */     this.d.addChangeListener(new SpinnerOptionsListener("Editor.Grid.lineZoomFactor", null));
/* 106:113 */     this.f.addChangeListener(new SpinnerOptionsListener("Editor.Grid.lineSpan", null));
/* 107:114 */     this.g.addItemListener(new CheckboxOptionsListener("Editor.TransparencyChessboard.showDefault", null));
/* 108:115 */     this.h.addChangeListener(new SpinnerOptionsListener("Editor.TransparencyChessboard.cellSize", null));
/* 109:116 */     this.j.addItemListener(new CheckboxOptionsListener("Editor.Zoom.wheelZooming", null));
/* 110:117 */     this.k.addItemListener(new CheckboxOptionsListener("Editor.Zoom.smartZooming", null));
/* 111:118 */     this.l.addChangeListener(new SpinnerOptionsListener("Editor.Zoom.prefferedWidth", null));
/* 112:119 */     this.n.addChangeListener(new SpinnerOptionsListener("Editor.Zoom.prefferedHeight", null));
/* 113:120 */     this.q.addActionListener(new ColorOptionsListener("Editor.Grid.lineColor", null));
/* 114:121 */     this.u.addActionListener(new ColorOptionsListener("Editor.TransparencyChessboard.whiteColor", null));
/* 115:122 */     this.t.addActionListener(new ColorOptionsListener("Editor.TransparencyChessboard.blackColor", null));
/* 116:123 */     this.w.getTextField().getDocument().addDocumentListener(new TextDocumentOptionsListener("ExternalEditor.executablePath"));
/* 117:    */     
/* 118:    */ 
/* 119:126 */     this.w.addActionListener(new ExternalEditorPathActionListener(null));
/* 120:    */     
/* 121:128 */     updateUI();
/* 122:    */   }
/* 123:    */   
/* 124:    */   public JPanel getContentPane()
/* 125:    */   {
/* 126:132 */     return this.a;
/* 127:    */   }
/* 128:    */   
/* 129:    */   private static class LinkEnabledListener
/* 130:    */     implements ItemListener
/* 131:    */   {
/* 132:    */     private final JComponent[] a;
/* 133:    */     
/* 134:    */     LinkEnabledListener(JComponent[] paramArrayOfJComponent)
/* 135:    */     {
/* 136:139 */       this.a = ((JComponent[])paramArrayOfJComponent.clone());
/* 137:    */     }
/* 138:    */     
/* 139:    */     public void itemStateChanged(ItemEvent paramItemEvent)
/* 140:    */     {
/* 141:143 */       a(paramItemEvent.getStateChange() == 1);
/* 142:    */     }
/* 143:    */     
/* 144:    */     private void a(boolean paramBoolean)
/* 145:    */     {
/* 146:147 */       for (JComponent localJComponent : this.a) {
/* 147:148 */         localJComponent.setEnabled(paramBoolean);
/* 148:    */       }
/* 149:    */     }
/* 150:    */   }
/* 151:    */   
/* 152:    */   public Options getOptions()
/* 153:    */   {
/* 154:154 */     return this.x;
/* 155:    */   }
/* 156:    */   
/* 157:    */   public void updateUI()
/* 158:    */   {
/* 159:159 */     EditorOptions localEditorOptions = this.x.getEditorOptions();
/* 160:160 */     ExternalEditorOptions localExternalEditorOptions = this.x.getExternalEditorOptions();
/* 161:    */     
/* 162:162 */     GridOptions localGridOptions = localEditorOptions.getGridOptions();
/* 163:163 */     this.b.setSelected(localGridOptions.isShowDefault());
/* 164:164 */     this.d.setValue(Integer.valueOf(localGridOptions.getLineZoomFactor()));
/* 165:165 */     this.f.setValue(Integer.valueOf(localGridOptions.getLineSpan()));
/* 166:166 */     this.q.setSelectedColor(localGridOptions.getLineColor());
/* 167:167 */     TransparencyChessboardOptions localTransparencyChessboardOptions = localEditorOptions.getTransparencyChessboardOptions();
/* 168:168 */     this.g.setSelected(localTransparencyChessboardOptions.isShowDefault());
/* 169:169 */     this.h.setValue(Integer.valueOf(localTransparencyChessboardOptions.getCellSize()));
/* 170:170 */     this.u.setSelectedColor(localTransparencyChessboardOptions.getWhiteColor());
/* 171:171 */     this.t.setSelectedColor(localTransparencyChessboardOptions.getBlackColor());
/* 172:172 */     ZoomOptions localZoomOptions = localEditorOptions.getZoomOptions();
/* 173:173 */     this.j.setSelected(localZoomOptions.isWheelZooming());
/* 174:174 */     this.k.setSelected(localZoomOptions.isSmartZooming());
/* 175:175 */     Dimension localDimension = localZoomOptions.getPrefferedSize();
/* 176:176 */     this.l.setValue(Integer.valueOf(localDimension.width));
/* 177:177 */     this.n.setValue(Integer.valueOf(localDimension.height));
/* 178:178 */     this.w.setText(localExternalEditorOptions.getExecutablePath());
/* 179:    */   }
/* 180:    */   
/* 181:    */   private final class CheckboxOptionsListener
/* 182:    */     implements ItemListener
/* 183:    */   {
/* 184:    */     private final String a;
/* 185:    */     
/* 186:    */     private CheckboxOptionsListener(String paramString)
/* 187:    */     {
/* 188:185 */       this.a = paramString;
/* 189:    */     }
/* 190:    */     
/* 191:    */     public void itemStateChanged(ItemEvent paramItemEvent)
/* 192:    */     {
/* 193:190 */       OptionsUIForm.this.x.setOption(this.a, Boolean.valueOf(1 == paramItemEvent.getStateChange()));
/* 194:    */     }
/* 195:    */   }
/* 196:    */   
/* 197:    */   private final class SpinnerOptionsListener
/* 198:    */     implements ChangeListener
/* 199:    */   {
/* 200:    */     private final String a;
/* 201:    */     
/* 202:    */     private SpinnerOptionsListener(String paramString)
/* 203:    */     {
/* 204:198 */       this.a = paramString;
/* 205:    */     }
/* 206:    */     
/* 207:    */     public void stateChanged(ChangeEvent paramChangeEvent)
/* 208:    */     {
/* 209:202 */       JSpinner localJSpinner = (JSpinner)paramChangeEvent.getSource();
/* 210:203 */       OptionsUIForm.this.x.setOption(this.a, localJSpinner.getValue());
/* 211:    */     }
/* 212:    */   }
/* 213:    */   
/* 214:    */   private final class ColorOptionsListener
/* 215:    */     implements ActionListener
/* 216:    */   {
/* 217:    */     private final String a;
/* 218:    */     
/* 219:    */     private ColorOptionsListener(String paramString)
/* 220:    */     {
/* 221:211 */       this.a = paramString;
/* 222:    */     }
/* 223:    */     
/* 224:    */     public void actionPerformed(ActionEvent paramActionEvent)
/* 225:    */     {
/* 226:215 */       ColorPanel localColorPanel = (ColorPanel)paramActionEvent.getSource();
/* 227:216 */       OptionsUIForm.this.x.setOption(this.a, localColorPanel.getSelectedColor());
/* 228:    */     }
/* 229:    */   }
/* 230:    */   
/* 231:    */   private final class TextDocumentOptionsListener
/* 232:    */     extends DocumentAdapter
/* 233:    */   {
/* 234:    */     private final String a;
/* 235:    */     
/* 236:    */     public TextDocumentOptionsListener(String paramString)
/* 237:    */     {
/* 238:224 */       this.a = paramString;
/* 239:    */     }
/* 240:    */     
/* 241:    */     protected void textChanged(DocumentEvent paramDocumentEvent)
/* 242:    */     {
/* 243:228 */       Document localDocument = paramDocumentEvent.getDocument();
/* 244:229 */       Position localPosition = localDocument.getStartPosition();
/* 245:    */       try
/* 246:    */       {
/* 247:231 */         OptionsUIForm.this.x.setOption(this.a, localDocument.getText(localPosition.getOffset(), localDocument.getLength()));
/* 248:    */       }
/* 249:    */       catch (BadLocationException localBadLocationException) {}
/* 250:    */     }
/* 251:    */   }
/* 252:    */   
/* 253:    */   private final class ExternalEditorPathActionListener
/* 254:    */     implements ActionListener
/* 255:    */   {
/* 256:    */     private ExternalEditorPathActionListener() {}
/* 257:    */     
/* 258:    */     public void actionPerformed(ActionEvent paramActionEvent)
/* 259:    */     {
/* 260:241 */       Application localApplication = ApplicationManager.getApplication();
/* 261:242 */       VirtualFile localVirtualFile = (VirtualFile)localApplication.runWriteAction(new NullableComputable()
/* 262:    */       {
/* 263:    */         public VirtualFile compute()
/* 264:    */         {
/* 265:244 */           String str = FileUtil.toSystemIndependentName(OptionsUIForm.this.w.getText());
/* 266:245 */           return LocalFileSystem.getInstance().refreshAndFindFileByPath(str);
/* 267:    */         }
/* 268:247 */       });
/* 269:248 */       FileChooserDescriptor localFileChooserDescriptor = new FileChooserDescriptor(true, SystemInfo.isMac, false, false, false, false);
/* 270:249 */       localFileChooserDescriptor.setShowFileSystemRoots(true);
/* 271:250 */       localFileChooserDescriptor.setTitle(ImagesBundle.message("select.external.executable.title", new Object[0]));
/* 272:251 */       localFileChooserDescriptor.setDescription(ImagesBundle.message("select.external.executable.message", new Object[0]));
/* 273:252 */       FileChooser.chooseFiles(localFileChooserDescriptor, null, localVirtualFile, new Consumer()
/* 274:    */       {
/* 275:    */         public void consume(List<VirtualFile> paramAnonymousList)
/* 276:    */         {
/* 277:255 */           String str = ((VirtualFile)paramAnonymousList.get(0)).getPath();
/* 278:256 */           OptionsUIForm.this.w.setText(str);
/* 279:    */         }
/* 280:    */       });
/* 281:    */     }
/* 282:    */   }
/* 283:    */ }



/* Location:           E:\idea\

 * Qualified Name:     org.intellij.images.options.impl.OptionsUIForm

 * JD-Core Version:    0.7.0.1

 */